<template>
  <el-table :data="dataSource" style="width: 100%">
    <el-table-column prop="id" label="编号" width="120"  align="center" />
    <el-table-column prop="tname" label="类型名称" width="160" align="center" />
    <el-table-column prop="turl" label="类型路径" width="160" align="center" />
    <el-table-column fixed="right" label="操作" width="250" align="center">
      <template #default="scope">
        <el-button
          link
          type="warning"
          size="small"
          @click="updateBlog(scope.row.id)"
          ><i class="iconfont icon-xiugai"></i>修改</el-button
        >
        <el-popconfirm
          title="确定删除吗？"
          confirm-button-text="是"
          cancel-button-text="不是"
          :hide-icon="true"
          @confirm="delBlog(scope.row.id)"
        >
          <template #reference>
            <el-button link type="danger" size="small"
              ><i class="iconfont icon-changyonggoupiaorenshanchu"></i
              >删除</el-button
            >
          </template>
        </el-popconfirm>
      </template>
    </el-table-column>
  </el-table>
</template>
<script setup>
import { ref,inject } from "vue";
import api from "@/axios";
let getTypeList = inject('getTypeList')
let openDialogWithId = inject('openDialogWithId')
const emit = defineEmits(["rowSelected", "rowClick"]);
const props = defineProps({
  dataSource: Object,
  showPagination: {
    type: Boolean,
    default: true,
  },
  options: {
    type: Object,
    default: {
      extHeight: 0,
      showIndex: false,
    },
  },
  fetch: Function, // 获取数据的函数
  initFetch: {
    type: Boolean,
    default: true,
  },
});

//顶部 60 , 内容区域距离顶部 20， 内容上下内间距 15*2  分页区域高度 46
const topHeight = 60 + 20 + 30 + 46;

const tableHeight = ref(
  props.options.tableHeight
    ? props.options.tableHeight
    : window.innerHeight - topHeight - props.options.extHeight
);

//删除功能
const delBlog = async (id) => {
  try {
    await api(`ptype/del?id=${id}`);
    ElMessage({
      message: "删除成功！",
      type: "success",
    });
    getTypeList();
  } catch (error) {
    ElMessage({
      message: "删除失败！",
      type: "error",
    });
  }
};

//更新功能
const updateBlog = (id)=>{
  openDialogWithId(id)
}
</script>
<style lang="scss">
.cover {
  width: 80px;
  height: 80px;
  img {
    width: 100%;
    height: 100%;
  }
}
</style>